#include <bits/stdc++.h>
using namespace std;
int t,n,m,l,sv,pl,maxn,minn,ans,ans2;
double c;
int p[100005],dc[100005],vc[100005],ac[100005];
struct node{
    int lef,rig;
}b[100005];
bool cmp(node asd,node dsa)
{
    if(asd.lef==dsa.lef)return asd.rig<=dsa.rig;
    return asd.lef<dsa.lef;
}
int findpl(int la)
{
    int le=1,ri=m,mid;
    while(le<ri)
    {
        mid=(le+ri)/2;
        if(p[mid]<la)
        {
            le=mid+1;
        }
        else
        {
            ri=mid;
        }
    }
    return le;
}
int findpr(int ra)
{
    int le=1,ri=m,mid;
    while(le<ri)
    {
        mid=(le+ri+1)/2;
        if(p[mid]>ra)
        {
            ri=mid-1;
        }
        else
        {
            le=mid;
        }
    }
    return ri;
}
bool check(int d,int v,int a)
{
    if(a==0&&v<=sv)return 0;
    if(a<0&&v<=sv)return 0;
    if(a>0&&v+(l-d)*a<=sv)return 0;
    return 1;
}
int main()
{
    freopen("detect.in","r",stdin);
    freopen("detect.out","w",stdout);
    cin>>t;
    while(t--)
    {
        cin>>n>>m>>l>>sv;
        for(int i=1;i<=n;i++)cin>>dc[i]>>vc[i]>>ac[i];
        for(int i=1;i<=m;i++)cin>>p[i];
        ans=0,ans2=0;
        for(int i=1;i<=n;i++)
        {
            if(check(dc[i],vc[i],ac[i])==1)
            {
                if(ac[i]==0&&vc[i]>sv)
                {
                    if(p[m]<dc[i])continue;
                    ans++;
                    b[ans].lef=findpl(dc[i]);
                    b[ans].rig=m;
                }
                else if(ac[i]<0)
                {
                    c=(vc[i]-sv)*1.0/(-ac[i]);
                    pl=ceil(dc[i]*1.0+vc[i]*1.0*c-0.5*ac[i]*c*c)-1;
                    ans++;
                    b[ans].lef=findpl(dc[i]);
                    b[ans].rig=findpr(pl);
                    if(b[ans].rig-b[ans].lef<0)
                    {
                        ans--;
                        continue;
                    }
                }
                else if(ac[i]>0)
                {
                    c=(sv-vc[i])*1.0/ac[i];
                    pl=floor(dc[i]*1.0+vc[i]*1.0*c+0.5*ac[i]*c*c)+1;
                    if(p[m]<pl)continue;
                    ans++;
                    b[ans].lef=findpl(pl);
                    b[ans].rig=m;
                }
            }
        }
        sort(b+1,b+ans+1,cmp);
        maxn=b[1].rig;
        minn=b[1].lef;
        for(int i=2;i<=ans;i++)
        {
            if(b[i].rig<minn||b[i].lef>maxn)
            {
               ans2++;
               maxn=b[i].rig;
               minn=b[i].lef;
            }
            else
            {
                maxn=min(maxn,b[i].rig);
                minn=max(minn,b[i].lef);
            }
        }
        cout<<ans<<" "<<m-ans2<<endl;
    }
    return 0;
}
